--[[
从上行短信队列KEYS[1]中读取[序列:号码],并读取其关联[KEYS[2]:序号:号码]HASH中的内容,返回指定长度的List

KEYS[1] : 短信序号队列
KEYS[2] : hash key前缀, 和KEYS[1]读取的字符串组成完整的hash key
ARGV[1] : 返回的最大list长度

--]]

local modeallist = KEYS[1]
local hashprefix = KEYS[2]
local count = tonumber(ARGV[1])
local array = {}
local index = 0

for i=1, count, 1 do
    local seqnum = redis.call("rpop", modeallist)
    if (seqnum ~= false and seqnum ~= "") then
        local sminfo = redis.call("hmget", hashprefix..":"..seqnum, "Srv_node", "User", "SendPort", "Smcont", "recvTime", "SerialSegment", "OrgSrvNode")
        index = index + 1
        table.insert(sminfo, seqnum)
        array[index] = sminfo
    else
        break
    end

    if (index >= count) then
        break
    end
end

return array